﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLToolkit.Data;
using SqlException = BLToolkit.Data.Sql.SqlException;

namespace PlatformManagement
{
    public partial class RestoreForm : DevComponents.DotNetBar.Metro.MetroForm
    {
        public RestoreForm()
        {
            InitializeComponent();
        }

        private void btnSt_Click(object sender, EventArgs e)
        {
            try
            {
                var db = new DbManager();
                db.Connection= new SqlConnection(@"data source=.\sqlexpress;database=master;Integrated Security =  true");
                string sqlRestore = "Restore Database ["+txtName.Text+"] from disk='"+txtLocation.Text+"'  WITH REPLACE";
                db.SetCommand(sqlRestore);
                db.ExecuteNonQuery();
                MessageBox.Show("Compeleted successfully! ");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, "Restore Database");
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "(*.bak)|*.bak";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                btnSt.Enabled = true;
                txtName.Enabled = true;
                txtLocation.Text = openFileDialog1.FileName;
            }
        }

    }
}
